/* eslint-disable no-undef */
var Web3 = require("web3");
var web3 = new Web3("http://121.36.62.77:8501");
var abi = [
  { inputs: [], stateMutability: "nonpayable", type: "constructor" },
  {
    inputs: [
      { internalType: "string", name: "domain", type: "string" },
      { internalType: "string", name: "IP", type: "string" },
    ],
    name: "addToMap",
    outputs: [],
    stateMutability: "nonpayable",
    type: "function",
  },
  {
    inputs: [{ internalType: "string", name: "domain", type: "string" }],
    name: "getIPbyDomain",
    outputs: [{ internalType: "string", name: "", type: "string" }],
    stateMutability: "view",
    type: "function",
  },
];
// 部署的合约地址
var address = "0x938413adbb68d036cdce826c108185a4f5e03c4b";

var dnsContract = new web3.eth.Contract(abi, address);
// 从合约查询
dnsContract.methods
  .getIPbyDomain("vortex.data.microsoft.com")
  .call()
  .then((result) => {
    console.log(result);
  });

// var accounts = "0xb172d5564fee6fa44608735fc2b56f00da768ce7";
// // 解锁账户合约
// web3.eth.personal
//   .unlockAccount(accounts, "123456", 600)
//   .then(console.log("Account unlocked!"));
// // 向合约写入
// dnsContract.methods
//   .addToMap("88.com", "8.8.8.8")
//   .send({ from: accounts })
//   .then(function (receipt) {
//     console.log(receipt);
//   });

// //   执行合约查询手续费估计
// dnsContract.methods
//   .addToMap("88.com", "8.8.8.8")
//   .estimateGas({ from: accounts })
//   .then(function (gasAmount) {
//     console.log(gasAmount);
//   })
//   .catch(function (error) {
//     console.log(error);
//   });
